package com.kklsqm.langchain4j.controller;

import com.kklsqm.langchain4j.assistant.DeepSeekAssistant;
import com.kklsqm.langchain4j.assistant.QwenAssistant;
import com.kklsqm.langchain4j.service.ILangChainTTSService;
import com.kklsqm.langchain4j.service.impl.LangChainTTSServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import static org.springframework.http.MediaType.TEXT_EVENT_STREAM_VALUE;

/**
 * 功能:
 * 作者: 沙琪马
 * 日期: 2025/4/21 14:27
 */
@RestController
@Slf4j
public class ChatController {

    @Resource
    private QwenAssistant assistant;

    @Resource
    private ILangChainTTSService ttsService;

    @Resource
    private LangChainTTSServiceImpl chatService;

    @Resource
    private DeepSeekAssistant commonAssistant;

    @GetMapping("/refine")
    public String model(@RequestParam(value = "message", defaultValue = "Hello") String message) {
        log.info("传入的参数:{}", message);
        log.info("传入的参数:{}", message);
        return assistant.chat(message);
    }

    @GetMapping("/extraInfo")
    public String refine(@RequestParam(value = "message", defaultValue = "Hello") String message,
                         @RequestParam(value="extraInfo", defaultValue = "") String extraInfo) {
        return ttsService.refineText(message, extraInfo);
    }

    // 主题：必填（生日、旅行、美食、自拍等）
    //
    //场景：可选（家庭、朋友、同事、情侣等）
    //
    //风格：可选（幽默、文艺、简洁、正能量等）
    //
    //字数：建议30-100字
    //
    //表情符号：是否添加（默认添加）
    @GetMapping("/extraInfoChat")
    public String generateCopywriting( @RequestParam(value="platform", defaultValue = "") String platform,
                                        @RequestParam(value="", defaultValue = "Hello") String message,
                                        @RequestParam(value="style", defaultValue = "") String style,
                                        @RequestParam(value="wordCount", defaultValue = "") String wordCount,
                                        @RequestParam(value="keyPoints", defaultValue = "") String keyPoints,
                                       @RequestParam(value="emoji", defaultValue = "true") Boolean emoji){
        return assistant.generateCopywriting(platform,message,style,wordCount,keyPoints, emoji);
    }

    /**
     * 流式聊天
     *
     * @param sessionId       会话id
     * @param role            设定角色
     * @param question        原始问题
     * @param webSearchEnable 是否开启网页搜索
     * @param extraInfo       额外信息（暂未实现）
     * @return
     */
    @GetMapping(value = "/stream/flux")
    public Flux<String> chatStreamFlux(@RequestParam(value = "sessionId") String sessionId,
                                       @RequestParam(value = "role", required = false, defaultValue = "智能问答助手") String role,
                                       @RequestParam(value = "question") String question,
                                       @RequestParam(value = "webSearchEnable", required = false, defaultValue = "false") Boolean webSearchEnable,
                                       @RequestParam(value = "extraInfo", required = false, defaultValue = "") String extraInfo) {
        return chatService.chatStreamFlux(commonAssistant, sessionId, role, question, extraInfo,"deepseek-chatt");
    }
}